GetReservoirById Function

public function GetReservoirById(list, id) result(p)

given a list of reservoirs, returns a pointer to one reservoir by id

Arguments

Type IntentOptional Attributes Name
type(Reservoir), intent(in), POINTER :: list
integer(kind=short), intent(in) :: id

Return Value type(Reservoir), POINTER


Variables

Type Visibility Attributes Name Initial
logical, public :: found

Source Code

FUNCTION GetReservoirById &
( list, id) &
RESULT (p)

IMPLICIT NONE 

!Arguments with intent in:
TYPE(Reservoir), POINTER, INTENT(IN) :: list !list of reservoirs
INTEGER(KIND = short), INTENT(IN)    :: id

!Arguments with intent out:
TYPE(Reservoir), POINTER :: p !pointer to reservoir

!local arguments:
LOGICAL :: found

!------------end of declaration------------------------------------------------

!loop througout list of reservoirs searching for id
p => list
found = .false.
DO WHILE (ASSOCIATED(p)) 
  IF (p % id == id) THEN
    found = .TRUE.
    EXIT
  ELSE
    p => p % next
  END IF
ENDDO

IF (.NOT. found ) THEN
  CALL Catch ('error', 'Reservoirs', 'reservoir not found by &
                       function GetReservoirById: ', argument = ToString(id))
END IF

RETURN
END FUNCTION GetReservoirById